<form id="form1" method="post">
	<input name="id" id="id" class="mini-hidden" value="0"/>
	<div style="padding-left:11px;padding-bottom:5px;">
		<table style="table-layout:fixed;">
			<tr>
				<td style="width:100px;">类型：</td>
				<td style="width:140px;"><input name="types" id="types" class="mini-textbox" value="1" style="width:100%;"/></td>
				<td style="width:100px;">数量：</td>
				<td style="width:140px;"><input name="count" id="count" vtype="range:1,1000" required="true" value="1" class="mini-spinner" style="width:100%;"/></td>
			</tr>
			<tr>
				<td style="width:100px;">领取/归还员工：</td>
				<td style="width:380px;" colspan="3"><input id="staff" name="staff" class="mini-buttonedit" onbuttonclick="onButtonEdit(this,'/common/staff')" style="width:100%;"/></td>
			</tr>
			<tr>
				<td style="width:100px;">设备S/N：</td>
				<td style="width:380px;" colspan="3"><input id="no" name="no" class="mini-textbox" style="width:100%;"/></td>
			</tr>
			<tr>
				<td style="width:100px;">设备名称：</td>
				<td style="width:380px;" colspan="3"><input id="device" name="device" class="mini-buttonedit" onbuttonclick="onButtonEdit(this,'/common/device')" style="width:100%;"/></td>
			</tr>
			<tr>
				<td style="width:100px;">备注：</td>
				<td style="width:380px;" colspan="3"><input name="remark" id="remark" class="mini-textarea" style="width:100%;height:80px;" emptyText="请输入描述"/></td>
			</tr>
		</table>
	</div>
	<div style="text-align:center;padding:10px;">   
		<a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>   
		<a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>   
	</div>
</form>
<script type="text/javascript">
mini.parse();
var form = new mini.Form("form1");
mini.get("types").disable();

// 保存数据
function SaveData() {
	form.validate();
	if (form.isValid() == false) return;
	if (mini.get("count").getValue()==0){
		parent.parent.$.dooDialog.alert("件数不能为0！");
		return false;
	}

	if ($.trim(mini.get("staff").getValue()) == ""){
		parent.parent.$.dooDialog.alert("员工不能为空，请输入！");
		return false;
	}

	if ($.trim(mini.get("staff").getValue()) == $.trim(mini.get("staff").getText())){
		parent.parent.$.dooDialog.alert("员工不能直接输入，请重新选择！");
		return false;
	}
	
	if ($.trim(mini.get("no").getValue()) == ""){
		parent.parent.$.dooDialog.alert("设备编号不能为空，请输入！");
		return false;
	}
	
	if ($.trim(mini.get("device").getValue()) == ""){
		parent.parent.$.dooDialog.alert("设备不能为空，请输入！");
		return false;
	}
	
	if ($.trim(mini.get("device").getValue()) == $.trim(mini.get("device").getText())){
		parent.parent.$.dooDialog.alert("设备不能直接输入，请重新选择！");
		return false;
	}
	
	$.ajax({
		type:"POST",
		url:"/business/receiveEdit",
		data:{data:form.getData(),name:mini.get("device").getText()},
		cache: false,
		success: function (text) {
			CloseWindow("save");
		},
		error: function (jqXHR, textStatus, errorThrown) {
			CloseWindow();
		}
	});
}

// 设置数据
function SetData(data) {
	if (data.action == "edit") {
		data = mini.clone(data);
		mini.get("id").setValue(data.id);
		mini.get("types").setValue(data.types);
	}
}

// 关闭窗口
function CloseWindow(action) {
	if (action == "close" && form.isChanged()) {
		if (confirm("数据被修改了，是否先保存？")) {
			return false;
		}
	}
	if (window.CloseOwnerWindow){
		return window.CloseOwnerWindow(action);
	}else{
		window.close();
	}
}

// 保存数据
function onOk(e) {
	SaveData();
}

// 取消数据
function onCancel(e) {
	CloseWindow("cancel");
}
</script>
